package com.developer.platform.domain.service.impl;

import com.developer.platform.domain.Role;
import com.developer.platform.domain.event.MenuEvent;
import com.developer.platform.domain.event.MenuEventPublisher;
import com.developer.platform.domain.repository.IRoleRepository;
import com.developer.platform.domain.service.IRoleService;
import java.util.List;
import org.springframework.stereotype.Service;

/**
 * @author ：qiaoliang
 * @date ：2020-11-09
 */
@Service
public class RoleServiceImpl implements IRoleService {

    private final IRoleRepository roleRepository;
    private final MenuEventPublisher menuEventPublisher;

    public RoleServiceImpl(IRoleRepository roleRepository,
                           MenuEventPublisher menuEventPublisher) {
        this.roleRepository = roleRepository;
        this.menuEventPublisher = menuEventPublisher;
    }

    @Override
    public void save(Role role, List<Long> ids) {
        roleRepository.save(role, ids);
        menuEventPublisher.asyncPublish(new MenuEvent());
    }

    @Override
    public void update(Role role, List<Long> ids) {
        roleRepository.updateById(role, ids);
        menuEventPublisher.asyncPublish(new MenuEvent());
    }

    @Override
    public void delete(long id) {
        roleRepository.delete(id);
        menuEventPublisher.asyncPublish(new MenuEvent());
    }
}
